﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    public static CameraController instance;
    public Transform target;
    private Vector3 targetPostion;
    public float height = 5;
    public float distance = 6;
    private Vector3 refV;
    private void Awake()
    {
        instance = this;
    }

    void Start()
    {
    }

    private void LateUpdate()
    {
        UpdatePos();
    }

    public void UpdatePos()
    {
        if (target != null)
        {
            targetPostion = target.position + height * target.up - distance * target.forward;
            transform.position = Vector3.SmoothDamp(transform.position, targetPostion, ref refV, 0); //smoothTime不等于0就抖
            transform.LookAt(target.position);
        }
    }

    private void OnDestroy()
    {
        target = null;
        instance = null;
    }
}



